package com.lmx.api.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lmx.api.common.ErrorCode;
import com.lmx.api.exception.BusinessException;
import com.lmx.api.mapper.InterfanceInfoMapper;
import com.lmx.commen.model.entity.InterfanceInfo;
import com.lmx.api.service.InterfanceInfoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
* @author lmx
* @description 针对表【interfance_info(接口信息表)】的数据库操作Service实现
* @createDate 2023-02-02 13:08:22
*/
@Service
public class InterfanceInfoServiceImpl extends ServiceImpl<InterfanceInfoMapper, InterfanceInfo>
    implements InterfanceInfoService {

    /**
     * 校验interfance对象是否合法
     * add是创建是的校验
     * */
    @Override
    public void validInterfanceInfo(InterfanceInfo interfanceInfo, boolean add) {
        if (interfanceInfo==null){
            throw new BusinessException(ErrorCode.PARAMS_ERROR);
        }

//     Long id = interfanceInfo.getId();
     String name = interfanceInfo.getName();
     String decprition = interfanceInfo.getDecprition();
     String url = interfanceInfo.getUrl();
     String method = interfanceInfo.getMethod();
     Integer status = interfanceInfo.getStatus();
     String requestheader = interfanceInfo.getRequestheader();
     String reposeheader = interfanceInfo.getReposeheader();


//     在创建用户时这些字段不能为空
     if (add){
         if (StringUtils.isAnyBlank(name,decprition,url,method,reposeheader,requestheader)){
             throw new BusinessException(ErrorCode.PARAMS_ERROR,"创建是不能为空");
         }
     }

//      密码传入0 1 以外的数字
     if (status != 0 && status != 1){
         throw new BusinessException(ErrorCode.PARAMS_ERROR,"接口状态错误");
     }

     if (decprition!=null && decprition.length()>=200){
         throw new BusinessException(ErrorCode.PARAMS_ERROR,"接口描述过长，限制在200字以内");
     }


     if (name!=null && name.length()>50){
         throw new BusinessException(ErrorCode.PARAMS_ERROR,"接口名字限制在50字以内");
     }





    }
}




